package cn.kgc.bilibili.controller;

import cn.kgc.bilibili.pojo.User;
import cn.kgc.bilibili.service.UserService;
import cn.kgc.bilibili.util.UserAlimessage;
import cn.kgc.bilibili.vo.UserVO;
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
public class UserController {
    @Resource
    private UserService userService;
    @GetMapping("login")
    public UserVO login(String phone,String password){
        UserVO userVO = new UserVO();
        User user = userService.login(phone);
        System.out.println(user);
        if(user!=null){
            if(user.getPassword().equals(password)){
                userVO.setUser(user);
                userVO.setStatus(true);
                userVO.setMsg("");
            }else{
                userVO.setStatus(false);
            }
        }else{
            userVO.setStatus(false);
        }
        return userVO;
    }
    @GetMapping("registerPassword")
    public UserVO registerPassword(String phone){
        UserVO userVO = new UserVO();
        User user = userService.registerPassword(phone);
        if(user!=null){
            userVO.setMsg("");
            userVO.setStatus(true);
            userVO.setUser(user);
        }else{
            userVO.setStatus(false);
        }
        return userVO;
    }
    @GetMapping("/biu")
    public Map<String,Object> sendSMS(String phone) {
        System.out.println("aaaaaaaaaaaa");
        System.out.println(phone);
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("code",UserAlimessage.Message(phone));
        return map;
    }
    @GetMapping("/updatePassword")
    public Map<String,Object> updatePassword(String password,Integer userid){
        Map<String,Object> map = new HashMap<>();
        System.out.println("密码"+password);
        System.out.println("用户编号"+userid);
        int i = userService.updatePassword(password, userid);
        System.out.println(i);
        if(i>0){
            map.put("msg","ok");
        }
        return map;
    }
    @GetMapping("/register")
    public Map<String,Object> register(String nickname,String phone,String password){
        Map<String,Object> map = new HashMap<>();
        System.out.println("aaaaaaaaaaaaaaaa");
        User user = new User();
        user.setNickname(nickname);
        user.setPassword(password);
        user.setPhone(phone);
        user.setGender("保密");
        user.setBirthday("2000-02-15 08:26:05");
        user.setDesc("这个人很懒");
        user.setHeadphoto("默认.jpg");
        user.setIsvip(0);
        user.setExp(0);
        user.setYingbi(0);
        System.out.println(user);
        int register = userService.register(user);
        if(register>0){
            map.put("msg","ok");
        }
        return map;
    }
}
